<template>
	<view class="hexiaodetail" :style="{'height':show?'100vh':''}">
		<headertop title="详情" :back1="back1"></headertop>
		<!-- 已取消 -->
		<image src="https://39gongli.oss-cn-beijing.aliyuncs.com/static/Group 11468@2x.png" class="hexiaodetail_back"
			mode="" v-if="contentobj.status==4"></image>
		<!-- 已完成 -->
		<image src="https://39gongli.oss-cn-beijing.aliyuncs.com/static/Group 11467@2x.png" class="hexiaodetail_back"
			mode="" v-if="contentobj.status==5"></image>
		<!-- 待发货 -->
		<image src="https://39gongli.oss-cn-beijing.aliyuncs.com/static/Group 11481@2x.png" class="hexiaodetail_back"
			mode="" v-if="contentobj.status==2"></image>
		<!-- 待支付 -->
		<image src="https://39gongli.oss-cn-beijing.aliyuncs.com/static/Group 11462@2x.png" class="hexiaodetail_back"
			mode="" v-if="contentobj.status==0"></image>
		<!-- 待收货 -->
		<image src="https://39gongli.oss-cn-beijing.aliyuncs.com/static/Group 11482@2x.png" class="hexiaodetail_back"
			mode="" v-if="contentobj.status==3"></image>
		<!-- 待核销 -->
		<image src="https://39gongli.oss-cn-beijing.aliyuncs.com/static/Group 11470@2x.png" class="hexiaodetail_back"
			mode="" v-if="contentobj.status==1"></image>


		<!-- 待发货 -->
		<view class="centerbox" v-if="contentobj.status==2">
			<view class="statustext">
				待发货
			</view>
			<view class="centerboxtext">
				您的订单正在处理中，敬请耐心等待~
			</view>
		</view>

		<!-- 已完成 -->
		<view class="centerbox" v-if="contentobj.status==5">
			<view class="statustext">
				已完成
			</view>
			<view class="centerboxtext">
				您的露营商城订单已成功完成！
			</view>
		</view>
		<!-- 已取消 -->
		<view class="centerbox" v-if="contentobj.status==4">
			<view class="statustext">
				已取消
			</view>
			<view class="centerboxtext">
				您的露营商城订单已成功取消
			</view>
		</view>


		<!-- 待核销 -->
		<view class="centerbox" v-if="contentobj.status==1">
			<view class="statustext" style="display: flex;align-items: center;">
				待核销 <view class="hexiaobtn">
					核销码：dhus
				</view>
			</view>
			<view class="centerboxtext">
				您的商品已准备就绪，出示核销码完成验证。
			</view>
		</view>

		<!-- 待支付 -->
		<view class="centerbox" v-if="contentobj.status==0">
			<view class="statustext">
				待支付
			</view>
			<view class="centerboxtext">
				您的订单仍未支付，请尽快付款~
			</view>
		</view>
		<!-- 待收货 -->
		<view class="centerbox" v-if="contentobj.status==3">
			<view class="statustext">
				待收货
			</view>
			<view class="centerboxtext">
				您的订单正在送货中，请留意包裹。
			</view>
		</view>

		<!-- 待收货 -->
		<view class="addressbox" v-if="contentobj.status==2||contentobj.status==3">
			<view class="addressboxline">
				<view class="topflex">
					<image src="/static/Frame@2x(7).png" class="addicon" mode=""></image>
					<view class="name">
						{{contentobj.username}}
					</view>
					<view class="mobile">
						{{contentobj.telphone}}
					</view>
				</view>
				<view class="addresstext">
					{{contentobj.address}}
				</view>
			</view>
		</view>
		<view class="dingdaninfo">
			<view class="infocenter" v-for="(item,index) in goodsarr" :key="index">
				<image :src="item.image" class="infocenter_img" mode=""></image>
				<view class="infocenter_rightbox">
					<view class="l1">
						<span style="width:400rpx">{{item.title}}</span>
					</view>
					<view class="l2">
						{{item.detail}}
					</view>
					<view class="l3">
						<view class="num">
							x{{item.num}}
						</view>
						<view class="jiage1">
							￥{{item.price}}
						</view>
					</view>
				</view>
			</view>
		</view>

		<!--已完成||使用中||待退还  -->
		<view class="yuyuebox">
			<view class="center">
				<view class="title">
					<view class="st">
					</view>
					<span>订单信息</span>
				</view>
				<view class="linexinxi">
					<view class="labletitle">
						订单类型：
					</view>
					<span>{{contentobj.ydtype}}</span>
				</view>
				<view class="linexinxi">
					<view class="labletitle">
						营位信息：
					</view>
					<span style="width:400rpx">{{contentobj.campfile}}</span>
				</view>
				<view class="linexinxi" v-if="contentobj.zhe">
					<view class="labletitle">
						会员折扣：
					</view>
					<span style="width:400rpx">{{contentobj.zhe}}折</span>
				</view>
			</view>
		</view>



		<view class="yuyuebox">
			<view class="center">
				<view class="title">
					<view class="st">
					</view>
					<span>支付信息</span>
				</view>
				<view class="linexinxi">
					<view class="labletitle">
						订单编号：
					</view>
					<span style="width:400rpx">{{contentobj.order_no}}</span>
				</view>
				<view class="linexinxi" v-if="contentobj.status!=0">
					<view class="labletitle">
						支付方式：
					</view>
					<span style="width:400rpx">{{contentobj.paytype==1?'微信支付':'余额支付'}}</span>
				</view>
				<view class="linexinxi">
					<view class="labletitle">
						下单时间：
					</view>
					<span style="width:400rpx">{{timestampfun(contentobj.createtime*1000)}}</span>
				</view>
				<view class="linexinxi" v-if="contentobj.status!=0">
					<view class="labletitle">
						支付时间：
					</view>
					<span style="width:400rpx">{{timestampfun(contentobj.paytime*1000)}}</span>
				</view>
				<view class="linexinxi" v-if="contentobj.status==5&&contentobj.emstype!=1">
					<view class="labletitle">
						核销时间：
					</view>
					<span style="width:400rpx">{{timestampfun(contentobj.offtime*1000)}}</span>
				</view>
			</view>
		</view>


		<view class="" style="height: 68rpx;">

		</view>
		<view class="" style="height: 184rpx;">

		</view>
		<view class="fixedbox"
			v-if="contentobj.status==1||contentobj.status==0||contentobj.status==3||contentobj.status==2">
			<!-- 待核销 -->
			<view class="centerbox" v-if="contentobj.status==1">
				<view class="btn1" @click="qxorder">
					取消订单
				</view>
				<view class="btn2" @click="hexiao">
					核销码
				</view>
			</view>
			<!-- 待支付 -->
			<view class="centerbox1" v-if="contentobj.status==0" @click="ljzf">
				立即支付
			</view>

			<!-- 待发货 -->
			<view class="centerbox1" v-if="contentobj.status==2" @click="qxorder">
				取消订单
			</view>
			<!-- 待核销 -->
			<view class="centerbox1" v-if="contentobj.status==3" @click="qdsh1">
				确定收货
			</view>
		</view>
		<up-popup :show="show" mode="center">
			<view class="popucenter">
				<image src="/static/Frame@2x(6).png" class="close" @click="show=false" mode="">
				</image>
				<view class="title">
					核销码
				</view>
				<canvas id="qrcode" canvas-id="qrcode"
					style="width: 332rpx;height: 332rpx;margin: 30rpx auto;"></canvas>
				<view class="btnss" @click="goResult(qrobj.hxnum)">
					核销码：{{qrobj.hxnum}}
				</view>
			</view>
		</up-popup>
	</view>
</template>

<script setup>
	import UQRCode from '@/uni_modules/Sansnn-uQRCode/js_sdk/uqrcode/uqrcode.js';
	import headertop from '@/components/header.vue'
	import {
		onPageScroll,
		onLoad
	} from "@dcloudio/uni-app";
	import {
		orderfile,
		payorder,
		changstatus
	} from '@/api/commodity.js'
	import {
		ref
	} from 'vue'
	const back1 = ref('')
	const contentobj = ref({})
	const qrobj = ref({})
	const goodsarr = ref([])
	const show = ref(false)
	onPageScroll((e) => {
		console.log(e, 'eeeeeeeeeeeeeee');
		if (e.scrollTop > 100) {
			back1.value = '#84BD78'
		} else {
			back1.value = ''
		}
	})

	function qdsh1() {
		uni.showModal({
			title: '提示', // 标题（可选）
			content: '确定要确认收货吗？', // 内容（可选）
			confirmText: '确定', // 确认按钮文字（可选，默认“确定”）
			cancelText: '取消', // 取消按钮文字（可选，默认“取消”）
			success: (res) => {
				if (res.confirm) {
					qdsh()
					// 执行确定后的逻辑
				} else if (res.cancel) {
					console.log('用户点击了取消');
					// 执行取消后的逻辑
				}
			},
			fail: (err) => {
				console.error('弹窗调用失败', err);
			}
		});
	}
	async function qdsh() {


		const res = await changstatus({
			id: contentobj.value.id,
			status: 2
		})
		if (res.data.code == 1) {
			setTimeout(() => {
				uni.showToast({
					title: '确认收货成功',
					icon: 'none'
				})
			}, 500)
			uni.navigateBack()
		} else {
			uni.showToast({
				title: res.data.msg,
				icon: 'none'
			})
		}
	}
	onLoad((opt) => {
		init(opt.id)
	})

	function qxorder() {
		uni.navigateTo({
			url: '/sub_my/my/quxiaoorder?id=' + contentobj.value.id
		})
	}

	function goResult(str) {
		uni.setClipboardData({
			data: str, // 需要复制的内容
			success: () => {
				// 成功提示框显示 1 秒钟
				uni.showToast({
					title: '复制成功',
					icon: 'success',
					duration: 1000
				});
			},
			fail: () => {
				// 失败提示框显示 1 秒钟
				uni.showToast({
					title: '复制失败，请重试',
					icon: 'none',
					duration: 1000
				});
			}
		});
	}

	async function init(id) {
		const res = await orderfile({
			id
		})
		if (res.data.code == 1) {
			contentobj.value = res.data.data.order
			goodsarr.value = res.data.data.goods
		}
	}

	function hexiao() {
		var item = contentobj.value
		// 获取uQRCode实例
		var qr = new UQRCode();
		// 设置二维码内容
		qr.data = item.hxnum
		// 设置二维码大小，必须与canvas设置的宽高一致
		qr.size = 166;
		// 调用制作二维码方法
		qr.make();
		// 获取canvas上下文
		var canvasContext = uni.createCanvasContext('qrcode', this); // 如果是组件，this必须传入
		// 设置uQRCode实例的canvas上下文
		qr.canvasContext = canvasContext;
		// 调用绘制方法将二维码图案绘制到canvas上
		qr.drawCanvas();
		show.value = true
		qrobj.value = item
	}
	async function ljzf() {

		const res = await payorder({
			id: contentobj.value.id
		})
		if (res.code == 0) {
			uni.showToast({
				title: res.msg,
				icon: 'none'
			})
			return
		}
		if (res.data.code == 1) {
			var payobj = res.data.data.pay
			uni.requestPayment({
				timeStamp: String(payobj.timestamp),
				nonceStr: payobj.noncestr,
				package: payobj.package,
				signType: 'MD5',
				paySign: payobj.sign,
				success(res) {
					uni.navigateBack();
					setTimeout(() => {
						uni.showToast({
							title: '成功',
							icon: 'none'
						})
					}, 500)

				},
				fail(e) {
					setTimeout(() => {
						uni.showToast({
							title: '支付失败',
							icon: 'none'
						})
					}, 500)

				}
			})
		} else {
			uni.showToast({
				title: res.data.msg,
				icon: 'none'
			})
		}
	}

	function timestampfun(time) {
		const date = new Date(time);
		const year = date.getFullYear();
		const month = String(date.getMonth() + 1).padStart(2, "0");
		const day = String(date.getDate()).padStart(2, "0");
		const hours = String(date.getHours()).padStart(2, "0");
		const minutes = String(date.getMinutes()).padStart(2, "0");
		const seconds = String(date.getSeconds()).padStart(2, "0");
		const formattedDate = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
		return formattedDate
	}
</script>
<style lang="scss">
	::v-deep .u-popup__content {
		background-color: rgba(255, 0, 0, 0) !important;
	}

	.popucenter {
		width: 592rpx;
		background: linear-gradient(180deg, #E8FFEA 0%, #FFFFFF 63%);
		border-radius: 28rpx 28rpx 28rpx 28rpx;
		overflow: hidden;
		position: relative;
		display: flex;
		flex-direction: column;
		align-items: center;

		.close {
			width: 48rpx;
			height: 48rpx;
			position: absolute;
			top: 0%;
			right: 0%;
			margin-right: 24rpx;
			margin-top: 24rpx;
		}

		.title {
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 36rpx;
			color: #1D2129;
			text-align: center;
			margin-top: 48rpx;
			width: 100%;
			margin-bottom: 50rpx;
		}

		.btnss {
			width: 256rpx;
			height: 56rpx;
			background: #7EBC79;
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 28rpx;
			color: #FFFFFF;
			text-align: center;
			line-height: 56rpx;
			margin-bottom: 44rpx;
		}

		.erweima {
			width: 332rpx;
			height: 332rpx;
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			margin: 30rpx auto;

		}
	}

	::v-deep .u-popup__content {
		background-color: rgba(255, 0, 0, 0) !important;
	}

	page {
		background: #F7F8FA;
	}

	.hexiaodetail {
		width: 100%;
		overflow: hidden;
		position: relative;

		.addressbox {
			width: 686rpx;
			height: 194rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 0rpx 14rpx 0rpx rgba(0, 0, 0, 0.15);
			border-radius: 24rpx 24rpx 24rpx 24rpx;
			margin: auto;
			overflow: hidden;
			margin-top: 28rpx;

			.addressboxline {
				width: 558rpx;
				margin: auto;
				margin-top: 28rpx;

				.addresstext {
					width: 558rpx;
					height: 68rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #777777;
					margin: auto;
					margin-top: 24rpx;
				}

				.topflex {
					width: 100%;
					display: flex;
					align-items: center;

					.addicon {
						width: 32rpx;
						height: 32rpx;
					}

					.name {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 32rpx;
						color: #333333;
						margin-left: 16rpx;
					}

					.mobile {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 32rpx;
						color: #333333;
						margin-left: 16rpx;
					}
				}
			}
		}

		.popucenter {
			width: 592rpx;
			background: linear-gradient(180deg, #E8FFEA 0%, #FFFFFF 63%);
			border-radius: 28rpx 28rpx 28rpx 28rpx;
			overflow: hidden;
			position: relative;
			display: flex;
			flex-direction: column;
			align-items: center;

			.close {
				width: 48rpx;
				height: 48rpx;
				position: absolute;
				top: 0%;
				right: 0%;
				margin-right: 24rpx;
				margin-top: 24rpx;
			}

			.title {
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 36rpx;
				color: #1D2129;
				text-align: center;
				margin-top: 48rpx;
				width: 100%;
				margin-bottom: 50rpx;
			}

			.btnss {
				width: 256rpx;
				height: 56rpx;
				background: #7EBC79;
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 28rpx;
				color: #FFFFFF;
				text-align: center;
				line-height: 56rpx;
				margin-bottom: 44rpx;
			}

			.erweima {
				width: 332rpx;
				height: 332rpx;
				border-radius: 0rpx 0rpx 0rpx 0rpx;
				margin: 30rpx auto;

			}
		}

		.fixedbox {
			width: 100%;
			height: 184rpx;
			background: #FFFFFF;
			box-shadow: 0rpx -4rpx 4rpx 0rpx rgba(0, 0, 0, 0.08);
			border-radius: 0rpx 0rpx 0rpx 0rpx;
			overflow: hidden;
			position: fixed;
			bottom: 0%;

			.centerbox1 {
				width: 686rpx;
				height: 88rpx;
				background: #7EBC79;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				text-align: center;
				line-height: 88rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 30rpx;
				color: #FFFFFF;
				margin: 22rpx auto;
			}

			.centerbox {
				width: 686rpx;
				height: 88rpx;
				overflow: hidden;
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin: 22rpx auto;

				.btn1 {
					width: 326rpx;
					height: 88rpx;
					background: rgba(126, 188, 121, 0.2);
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					border: 2rpx solid #E8F3FF;
					font-weight: 400;
					font-size: 30rpx;
					color: #7EBC79;
					text-align: center;
					line-height: 88rpx;
				}

				.btn2 {
					width: 326rpx;
					height: 88rpx;
					background: #7EBC79;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					border: 2rpx solid #E8F3FF;
					font-weight: 400;
					font-size: 30rpx;
					color: #FFFFFF;
					text-align: center;
					line-height: 88rpx;
				}
			}
		}

		&_back {
			width: 100%;
			height: 530rpx;
			position: absolute;
			z-index: -1;
		}

		.yuyuebox {
			width: 686rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 0rpx 14rpx 0rpx rgba(0, 0, 0, 0.15);
			border-radius: 24rpx 24rpx 24rpx 24rpx;
			overflow: hidden;
			margin: auto;
			margin-top: 28rpx;

			.center {
				width: 630rpx;
				overflow: hidden;
				margin: auto;
				margin-top: 34rpx;

				.linexinxi {
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 28rpx;
					color: #4E5969;
					display: flex;
					align-items: center;
					margin-bottom: 30rpx;

					.labletitle {
						width: 140rpx;
						color: #1D2129;
					}
				}

				.title {
					font-weight: bold;
					font-size: 32rpx;
					color: #1D2129;
					display: flex;
					align-items: center;
					margin-bottom: 28rpx;

					.st {
						width: 6rpx;
						height: 36rpx;
						background: #7EBC79;
						border-radius: 0rpx 24rpx 24rpx 0rpx;
						margin-right: 12rpx;
					}
				}
			}
		}

		.dingdaninfo {
			width: 686rpx;
			margin: auto;
			margin-top: 28rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 0rpx 14rpx 0rpx rgba(0, 0, 0, 0.15);
			border-radius: 24rpx 24rpx 24rpx 24rpx;
			overflow: hidden;

			.bottomline {
				width: 630rpx;
				height: 84rpx;
				border-top: 1rpx solid #F7F8FA;
				margin: auto;
				display: flex;
				align-items: center;

				.yajin {
					font-weight: 400;
					font-size: 24rpx;
					color: #86909C;
					margin-left: 208rpx;
					margin-top: 5rpx;
				}

				.cdf {
					margin-left: 32rpx;
					font-weight: 400;
					font-size: 24rpx;
					color: #86909C;
				}
			}

			.infocenter {
				width: 630rpx;
				display: flex;
				align-items: center;
				margin: 24rpx auto;
				justify-content: space-between;


				&_img {
					width: 162rpx;
					height: 144rpx;
					border-radius: 20rpx 20rpx 20rpx 20rpx;
				}

				&_rightbox {
					overflow: hidden;
					width: 412rpx;

					.l1 {
						display: flex;
						align-items: center;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 32rpx;
						color: #1D2129;

						.gu {
							width: 48rpx;
							height: 32rpx;
							background: #7EBC79;
							border-radius: 4rpx 16rpx 4rpx 16rpx;
							text-align: center;
							line-height: 32rpx;
							font-weight: 500;
							font-size: 24rpx;
							color: #FFFFFF;
							margin-right: 8rpx;
						}
					}

					.l3 {
						width: 100%;
						display: flex;
						justify-content: space-between;
						align-items: center;
						margin-top: 24rpx;

						.num {
							font-family: PingFang SC, PingFang SC;
							font-weight: 400;
							font-size: 26rpx;
							color: #868686;
						}

						.jiage1 {
							font-family: PingFang SC, PingFang SC;
							font-weight: bold;
							font-size: 36rpx;
							color: #7EBC79;
						}
					}

					.l2 {
						width: 412rpx;
						white-space: nowrap;
						/* 防止文本换行 */
						overflow: hidden;
						/* 隐藏超出容器的部分 */
						text-overflow: ellipsis;
						/* 超出部分显示为省略号 */
						margin-top: 20rpx;
						font-weight: 400;
						font-size: 26rpx;
						color: #868686;
					}

					.jiage {
						font-weight: bold;
						font-size: 36rpx;
						color: #7EBC79;
						margin-left: 294rpx;
						margin-top: 24rpx;
					}
				}
			}


		}

		.centerbox {
			margin: auto;
			width: 686rpx;
			margin-top: 190rpx;
			overflow: hidden;

			.statustext {
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 40rpx;
				color: #FFFFFF;

				.hexiaobtn {
					width: 208rpx;
					height: 44rpx;
					background: #FFFFFF;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					text-align: center;
					line-height: 44rpx;
					font-weight: bold;
					font-size: 28rpx;
					color: #538F46;
					margin-left: 22rpx;
				}
			}

			.centerboxtext {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				color: #FFFFFF;
				margin-top: 14rpx;
			}
		}
	}
</style>